from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime
from decimal import Decimal

class CustomerBase(BaseModel):
    name: str = Field(..., max_length=50)
    phone: str = Field(..., max_length=20)
    notes: Optional[str] = None

class CustomerCreate(CustomerBase):
    user_id: Optional[int] = None

class CustomerUpdate(BaseModel):
    name: Optional[str] = None
    phone: Optional[str] = None
    notes: Optional[str] = None
    member_discount: Optional[Decimal] = None

class CustomerResponse(CustomerBase):
    id: int
    user_id: Optional[int] = None
    member_discount: Decimal
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True

class CustomerWithProjects(CustomerResponse):
    project_count: int = 0
    latest_project_status: Optional[str] = None

